//
//  CSBMesdfCell.swift
//  CurSodoboAer
//
//  Created by CurSodoboAer on 2024/11/6.
//

import UIKit

class CSBMesdListfCell: UITableViewCell {
    var csbColoter:UIColor = .brown
    var csbFplowe:CGFloat = 23.1
    var csbHeihei:UIFont?
    
    
    let mychatContetnCSBLab = UILabel.init()
    let headCCSBL = UIImageView.init()
    let userNameCSBLab = UILabel.init()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        self.backgroundColor = .clear
        
        headCCSBL.layer.cornerRadius = 37.xQQ
        headCCSBL.layer.masksToBounds = true
        headCCSBL.contentMode = .scaleAspectFill
        if csbColoter == UIColor.black {
            csbHeihei = UIFont.systemFont(ofSize: csbFplowe)
            self.backgroundColor = csbColoter
        }else{
            csbHeihei = UIFont.systemFont(ofSize: csbFplowe + 1)
        }
        guard csbHeihei != nil else { return  }

        if self.backgroundColor == csbColoter {
            let qurk = UIButton(configuration: UIButton.Configuration.plain())
            qurk.isHidden = true
            qurk.isEnabled = false
            addSubview(qurk)
        }
        mychatContetnCSBLab.textColor = .white
        mychatContetnCSBLab.textAlignment = .left
        mychatContetnCSBLab.font = UIFont(name: "Kailasa Bold", size: 14)
        
        
        userNameCSBLab.textColor = .white
        userNameCSBLab.textAlignment = .left
        userNameCSBLab.font = UIFont(name: "Kailasa Bold", size: 16)
        
        contentView.addSubview(headCCSBL)
        contentView.addSubview(userNameCSBLab)
        contentView.addSubview(mychatContetnCSBLab)
        headCCSBL.snp.makeConstraints { make in
            make.width.height.equalTo(74.xQQ)
            make.centerY.equalToSuperview()
            make.leading.equalToSuperview().inset(12.xQQ)
        }
        
        userNameCSBLab.snp.makeConstraints { make in
            make.top.equalTo(headCCSBL.snp.top).offset(15.xQQ)
            make.leading.equalTo(headCCSBL.snp.trailing).offset(10.xQQ)
            make.trailing.equalToSuperview().inset(20)
        }
        
        mychatContetnCSBLab.snp.makeConstraints { make in
            make.top.equalTo(userNameCSBLab.snp.bottom).offset(6.xQQ)
            make.leading.equalTo(headCCSBL.snp.trailing).offset(10.xQQ)
            make.trailing.equalToSuperview().inset(20)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}


class CSBMesgrChatCell: UITableViewCell {
    
    let mychatContetnCSBLab = UILabel.init()
    let chatBackfCSB = UIView.init()
    
    private var cakeCSB:Dictionary<String,CGPoint>?
    private var fookCSB: UITextField?

    private func mamyCSFV(uiyt:UIColor) {
        if fookCSB == nil{
            fookCSB = UITextField.init()
            fookCSB?.backgroundColor = uiyt
            fookCSB?.leftViewMode = .never
            fookCSB?.placeholder = nil
        }
        
        
        if cakeCSB == nil{
            cakeCSB = Dictionary.init()
        }
        
        var poinrtCSB = CGPoint.init(x: 23, y: 34)
        
        cakeCSB?["\(CGFloat.random(in: 0...5))"] = poinrtCSB
        
        if fookCSB?.text == nil {
            cakeCSB?["\(CGFloat.random(in: 5...20))"] = poinrtCSB
        }
        poinrtCSB.y += 10
        
        if cakeCSB?.keys.count ?? 0 > 0 {
            
        }
        
        if poinrtCSB.y > 2 && poinrtCSB.x > 2 {
            
        }
        
    }
    let headSCB = UIImageView()
    
    func updateUIREmaklCSB(ismeCSB:Bool) {
        var csbBayui = [Int]()
        let csbNUmber = Array(repeating: 10, count: 64)
        let csbNumbe2 = Array(repeating: 96, count: 50)
        var cabSunmAll: Int = 0

        csbBayui.append(11)
        cabSunmAll = csbNUmber.count
        if cabSunmAll > 5 {
            csbBayui.append(contentsOf: csbNUmber)
        }else{
            csbBayui.append(contentsOf: csbNumbe2)
        }

        
        if ismeCSB == true{
            headSCB.isHidden = true
            csbBayui.append(contentsOf: [52, 6, 11])
            csbBayui.removeLast()
            cabSunmAll = csbBayui.count

            if (cabSunmAll >= 0) && (csbBayui.count >= 0) {
                chatBackfCSB.backgroundColor = .clear
                chatBackfCSB.layer.borderColor = UIColor.white.cgColor
                chatBackfCSB.layer.borderWidth = 1
            }
           
            mychatContetnCSBLab.textAlignment = .right
            chatBackfCSB.snp.remakeConstraints { make in
                make.width.lessThanOrEqualTo(280.xQQ)
                make.right.equalToSuperview().inset(12.xQQ)
                make.top.bottom.equalToSuperview().inset(14)
               
                make.width.greaterThanOrEqualTo(65.xQQ)
            }
        }else{
            headSCB.isHidden = false
            chatBackfCSB.backgroundColor = UIColor(red: 0.07, green: 0.07, blue: 0.07, alpha: 1)
            mychatContetnCSBLab.textAlignment = .left
            chatBackfCSB.snp.remakeConstraints { make in
                make.width.lessThanOrEqualTo(270.xQQ)
                make.left.equalTo(headSCB.snp.right).offset(12.xQQ)
                make.top.bottom.equalToSuperview().inset(14)
               
                make.width.greaterThanOrEqualTo(65.xQQ)
            }
            
            
        }
    }
    
  
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        backgroundColor = .clear
        contentView.addSubview(headSCB)
        contentView.addSubview(chatBackfCSB)
        headSCB.layer.cornerRadius = 22.xQQ
        headSCB.layer.masksToBounds = true
        headSCB.contentMode = .scaleAspectFill
        
        chatBackfCSB.addSubview(mychatContetnCSBLab)
        
        mychatContetnCSBLab.font = UIFont(name: "Helvetica", size: 15)
        mychatContetnCSBLab.textColor = .white
        chatBackfCSB.backgroundColor = UIColor.white
        chatBackfCSB.layer.cornerRadius = 20
        chatBackfCSB.layer.masksToBounds = true
        chatBackfCSB.contentMode = .scaleAspectFill
        
        
        
        headSCB.snp.makeConstraints { make in
            make.leading.equalToSuperview().inset(12.xQQ)
            make.width.height.equalTo(44.xQQ)
            make.top.equalToSuperview().inset(14.xQQ)
        }
        
        chatBackfCSB.snp.makeConstraints { make in
            make.width.lessThanOrEqualTo(270.xQQ)
            make.left.equalTo(headSCB.snp.right).offset(12.xQQ)
            make.top.bottom.equalToSuperview().inset(14)
           
            make.width.greaterThanOrEqualTo(65.xQQ)
        }
        
        mychatContetnCSBLab.snp.makeConstraints { make in
            make.leading.trailing.equalToSuperview().inset(17.xQQ)
            make.top.bottom.equalToSuperview().inset(16.xQQ)
        }
    }

    
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
